from appium import webdriver
from appium.webdriver.webdriver import WebDriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class Base():
    def __init__(self):
        cap={
              "platformName": "Android",
              "appium:deviceName": "emulator-5554",
              "appium:automationName": "uiautomator2",
              "appium:appPackage": "com.achievo.vipshop",
              "appium:appActivity": ".homepage.activity.MainActivity",
              "appium:noReset": True
            }

        self.driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub',cap) # 建立连接
        self.driver.implicitly_wait(20) # 隐式等待

    # 找元素
    def find_loc(self,loc):
        ele=self.driver.find_element(*loc)
        return ele
    # 显示等待
    def find_ele_wait(self,loc):
        ele=WebDriverWait(self.driver,20).until(EC.element_to_be_clickable(loc))
        return ele
    # 滑动
    def hua(self,a,b,c,d):
        self.driver.swipe(a,b,c,d,300)
    # 轻敲
    def qiao(self,x,y):
        self.driver.tap([(x,y)],300)
    # 截屏
    def jieping(self,s):
        self.driver.save_screenshot(s)
    # 退出
    def tui(self):
        self.driver.quit()
    # 按键
    def anjian(self,a):
        self.driver.press_keycode(a)